var app = getApp(), api = getApp().api;

Page({
    data: {
        list: [],
        shop: {}
        // ,
        // list:[
        //     {
        //         name:"文化科",
        //         id:1,
        //         list:[
        //             {
        //                 name:"语文",
        //                 id:2
        //             },
        //             {
        //                 name:"数学",
        //                 id:3
        //             }
        //         ]
        //     },
        //     {
        //         name:"文化科1",
        //         id:4,
        //         list:[
        //             {
        //                 name:"语文1",
        //                 id:5
        //             },
        //             {
        //                 name:"数学1",
        //                 id:6
        //             }
        //         ]
        //     }
        // ]
    },
    classfenlei:function(){
        console.log(this.__data__.mch_id,'tttttttttt')
          var id=this.__data__.mch_id;
        wx.navigateTo({
          url: '/mch/shop-cat/shop-cat?mch_id=' + id,
        })
      },
      shouye:function(){
        console.log(this.__data__.mch_id,'tttttttttt')
        var id=this.__data__.mch_id;
        wx.navigateTo({
          url: '/mch/shop/shop?mch_id=' + id,
        })
      },
      jieshao:function(){
        console.log(this.__data__.mch_id,'tttttttttt')
        var id=this.__data__.mch_id;
        wx.navigateTo({
          url: '/mch/shop-summary/shop-summary?mch_id=' + id,
        })
      },
      js:function(){
        console.log(this.__data__.mch_id,'tttttttttt')
        var id=this.__data__.mch_id;
        wx.navigateTo({
          url: '/mch/institutional-community/institutional-community?mch_id=' + id,
        })
      }
    ,  zhibo:function(){
      console.log(this.__data__.mch_id,'tttttttttt')
      var id=this.__data__.mch_id;
        wx.navigateTo({
          url: '/lives/admin/goods-list/goods-list?mch_id=' + id,
        })
      },
    onLoad: function(t) {
        getApp().page.onLoad(this, t);
        console.log(t.mch_id)
        wx.showLoading({
          title: '加载中...',
        })
        var a = this;
        var key = "shop_data_mch_id_" + t.mch_id;
        var shop_data = getApp().core.getStorageSync(key);
        a.setData({
            shop: shop_data.shop,
            cs_icon: shop_data.shop.cs_icon,
            mch_id: t.mch_id,
            cat_id: t.cat_id || ""
        });
        console.log(shop_data.cs_icon)
        var e = "shop_cat_list_mch_id_" + a.data.mch_id, i = getApp().core.getStorageSync(e);
        i && a.setData({
            list: i
        }),getApp().core.showNavigationBarLoading(), getApp().request({
            url: getApp().api.mch.course_cat,
            data: {
                mch_id: a.data.mch_id
            },
            success: function(t) {
                0 == t.code && (a.setData({
                    list: t.data.list,
                    shop: t.data.shop
                }), getApp().core.setStorageSync(e, t.data.list));
            },
            complete: function() {
                wx.hideLoading()
                getApp().core.hideNavigationBarLoading();
            }
        });
    },
    goToScanCodePay: function () {
        getApp().core.redirectTo({
            url: "/pages/scan-code-pay/scan-code-pay?mch_id=" + this.data.mch_id
        });
    },
    map_power: function () {
        var o = this;
        getApp().getConfig(function (t) {
            var e = o.data.shop;
            void 0 !== e ? o.map_goto(e) : getApp().core.getSetting({
                success: function (t) {
                    t.authSetting["scope.userLocation"] ? o.map_goto(e) : getApp().getauth({
                        content: "需要获取您的地理位置授权，请到小程序设置中打开授权！",
                        cancel: !1,
                        author: "scope.userLocation",
                        success: function (t) {
                            t.authSetting["scope.userLocation"] && o.map_goto(e);
                        }
                    });
                }
            });
        });
    },
    map_goto: function (t) {
        getApp().core.openLocation({
            latitude: parseFloat(t.latitude),
            longitude: parseFloat(t.longitude),
            address: t.address
        });
    },
    callPhone: function (t) {
        getApp().core.makePhoneCall({
            phoneNumber: t.target.dataset.info
        });
    },
    onClick: function () {
        wx.navigateTo({
          url: '/pages/search/search?mch_id='+this.data.mch_id,
        })
    },
    onReady: function() {
        getApp().page.onReady(this);
    },
    onShow: function() {
        getApp().page.onShow(this);
    },
    onHide: function() {
        getApp().page.onHide(this);
    },
    onUnload: function() {
        getApp().page.onUnload(this);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},

    shouye: function () {
        var id = this.__data__.mch_id;
        wx.redirectTo({
            url: '/mch/shop/shop?mch_id=' + id,
        })
    },
    jieshao: function () {
        var id = this.__data__.mch_id;
        wx.redirectTo({
            url: '/mch/shop-summary/shop-summary?mch_id=' + id,
        })
    },
    js: function () {
        var id = this.__data__.mch_id;
        wx.redirectTo({
            url: '/mch/institutional-community/institutional-community?mch_id=' + id,
        })
    },
    zhibo: function () {
        var id = this.__data__.mch_id;
        wx.redirectTo({
            url: '/lives/admin/goods-list/goods-list?mch_id=' + id,
        })
    },

    onShareAppMessage: function () {
        getApp().page.onShareAppMessage(this);
        var t = this;
        return {
          path: "/mch/shop/shop?user_id=" + getApp().getUser().id + "&mch_id=" + t.data.mch_id + '&store_id=' + (wx.getStorageSync("store_id") ? wx.getStorageSync("store_id") : 0),
          title: t.data.shop ? t.data.shop.name : "机构首页"
        };
    }
});